<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta charset=UTF-8>
<title></title>
<script src="${webroot }js/jquery.min.js"></script>
<script src="${webroot }js/bootstrap.min.js"></script>
<script src="${webroot }js/web.config.js"></script>
<script src="${webroot }js/func.action.js"></script>
<link rel="stylesheet" href="${webroot }css/bootstrap.min.css">
<link rel="stylesheet" href="${webroot }css/common.css">
<link rel="stylesheet" href="${webroot }css/client.css">
</head>
<body>
	<table class="table">
		<caption>
			<a data-toggle="modal" data-target="#myModal">添加教学楼</a>
		</caption>
		<thead>
			<tr>
				<td>编号</td>
				<td>楼名</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list }" var="bu">
				<tr>
					<td>${bu.buId }</td>
					<td>${bu.buName }</td>
					<c:if test="${bu.buStatus!=1 }">
						<td><a href="#" onclick="updateBuStatus(${bu.buId},1)">启用</a>
							&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#" onclick="delBu(${bu.buId})">删除</a>
						</td>
					</c:if>
					<c:if test="${bu.buStatus==1 }">
						<td><a href="#" onclick="updateBuStatus(${bu.buId},2)">禁用</a>
							&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#" onclick="delBu(${bu.buId})">删除</a>
							&nbsp;&nbsp;|&nbsp;&nbsp; <a href="${webroot }web/classroom/query?page=1&buId=${bu.buId}&status=1">教室</a></td>
					</c:if>
				</tr>
			</c:forEach>
		</tbody>
	</table>

	<div class="info_footer">
		<div class="footer_con">

			<div class="btn-group dropup info_choose ">
				<span class="dropdown-toggle" id="status_menu" role="0"
					data-toggle="dropdown"> <c:if test="${status == 0 }">全部类型</c:if>
					<c:if test="${status == 1 }">激活状态</c:if> <c:if
						test="${status == 2 }">禁用状态</c:if>
				</span> <span class="caret"></span>
				<ul class="dropdown-menu" role="menu" id="status_item">
					<li><a href="${webroot }web/building/query?page=1&status=0">全部状态</a>
					</li>
					<li><a href="${webroot }web/building/query?page=1&status=1">激活状态</a>
					</li>
					<li><a href="${webroot }web/building/query?page=1&status=2">禁用状态</a>
					</li>
				</ul>
			</div>
			<div class="info_page">
				<ul class="pagination">
					<li><a id="pre_page" role="1" href="#">&laquo;</a></li>
					<li><a id="next_page" role="2" href="#">&raquo;</a></li>
				</ul>
				<div class="btn-group dropup">
					<button type="button" class="btn btn-default dropdown-toggle"
						id="page_menu" data-toggle="dropdown">
						第 ${page } 页<span class="caret"></span>
					</button>
					<ul class="dropdown-menu" role="menu" id="info_page">

					</ul>
				</div>
			</div>

		</div>
	</div>

	<div class="hidden_area">
		<input type="hidden" value="${page }" id="page"> 
		<input type="hidden" value="${pages }" id="pages"> 
		<input type="hidden" value="${status }" id="status">
	</div>
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">修改密码</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label class="login_label">楼名：</label> <input
							class="form-control login_input" id="focusedInput" type="text"
							placeholder="请输入教学楼名字" name="buName">
					</div>
				</div>
				<div class="modal-footer">
					<span id="res_msg"></span>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" id="sure" class="btn btn-primary">提交</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
	<script type="text/javascript">
    $(document).ready(function(){
    	$("#sure").click(function(){
    		var name = $("[name='buName']").val();
    		$.ajax({
    			url : webRoot+"/web/building/add",
    			type:"post",
    			dataType:"json",
    			data:{
    				"buName":name
    			},
    			success:function(data){
    				if(data.result == "success"){
    					alert("操作成功！请继续操作");
    					$("[name='buName']").val("");
    				}else{
    					alert("操作失败！");
    				}
    			}
    		});
    	});
    	$("#pre_page").click(function(){
    		var page = $("#page").val();
    		if(page <= 1){
    			alert("已经是第一页了");
    		}else{
    			var now = page - 1;
    			var status = $("#status").val();
    			window.location.href= webRoot + "web/building/query?page="+now+"&status="+status;
    		}
    	});
    	$("#next_page").click(function(){
    		var page = $("#page").val();
    		var pages = $("#pages").val();
    		if(pages <= page){
    			alert("已经是最后一页了");
    		}else{
    			var now = parseInt(page) + 1;
    			var status = $("#status").val();
    			window.location.href= webRoot + "web/building/query?page="+now+"&status="+status;
    		}
    	});
    	
    	var page = $("#page").val();
    	var pages = $("#pages").val();
    	var status = $("#status").val();
    	var doc_page = $("#info_page");
    	doc_page.empty();
    	for (var i = 0; i < pages; i++) {
    		var cur = i + 1;
    		if (i != (page - 1)) {
    			doc_page.append("<li><a href='"+webRoot+"web/building/query?page="+cur+"&status="+status+"'>第"+cur+"页</a></li>");
    		}
    	}
    });
  </script>
</body>
</html>